/**
 * 提现帐号管理初始化
 */
var WithdrawtAccount = {
    id: "WithdrawtAccountTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
WithdrawtAccount.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '帐号', field: 'accountNo', visible: true, align: 'center', valign: 'middle'},
            {title: '账户名', field: 'accountName', visible: true, align: 'center', valign: 'middle'},
            {title: '账号类型', field: 'accountType', visible: true, align: 'center', valign: 'middle',formatter:"accountTypeFormatter"},
            {title: '账号属性', field: 'accountProp', visible: true, align: 'center', valign: 'middle',formatter:"accountPropFormatter"},
            {title: '开户证件类型', field: 'idType', visible: true, align: 'center', valign: 'middle',formatter:"idTypeFormatter"},
            {title: '身份证', field: 'idNo', visible: true, align: 'center', valign: 'middle'},
            {title: '手机号', field: 'tel', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
    ];
};

function accountTypeFormatter(value, row, index){
	if (value == 00) {
		return '银行卡';
	} else if(value == 01) {
		return '存折';
	}else if(value == 02) {
		return '信用卡';
	}
}

function accountPropFormatter(value, row, index){
	if (value == 0) {
		return '私人';
	} else if(value == 1) {
		return '公司';
	}
}


function idTypeFormatter(value, row, index){
	if (value == 0) {
		return '身份证';
	} else if(value == 1) {
		return '户口簿';
	}else if(value == 2) {
		return '护照';
	}else if(value == 3) {
		return '军官证';
	}else if(value == 4) {
		return '士兵证';
	}else if(value == 5) {
		return '港澳居民来往内地通行证';
	}else if(value == 6) {
		return '台湾同胞来往内地通行证';
	}else if(value == 7) {
		return '临时身份证';
	}else if(value == 8) {
		return '外国人居留证';
	}else if(value == 9) {
		return '警官证';
	}else if(value =="X") {
		return '其他证件';
	}
}


/**
 * 检查是否选中
 */
WithdrawtAccount.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        WithdrawtAccount.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加提现帐号
 */
WithdrawtAccount.openAddWithdrawtAccount = function () {
    var index = layer.open({
        type: 2,
        title: '添加提现帐号',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/withdrawtAccount/withdrawtAccount_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看提现帐号详情
 */
WithdrawtAccount.openWithdrawtAccountDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '提现帐号详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/withdrawtAccount/withdrawtAccount_update/' + WithdrawtAccount.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除提现帐号
 */
WithdrawtAccount.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/withdrawtAccount/delete", function (data) {
            Feng.success("删除成功!");
            WithdrawtAccount.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("withdrawtAccountId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询参数
 */
WithdrawtAccount.formParams = function() {
    var queryData = {};
    queryData['accountName'] = $("#accountName").val();
    queryData['tel'] = $("#tel").val();
    queryData['accountType'] = $("#accountType").val();
    queryData['accountProp'] = $("#accountProp").val();

    return queryData;
}

/**
 * 查询提现帐号列表
 */
WithdrawtAccount.search = function () {
	WithdrawtAccount.table.refresh({query: WithdrawtAccount.formParams()});
};

$(function () {
    var defaultColunms = WithdrawtAccount.initColumn();
    var table = new BSTable(WithdrawtAccount.id, "/withdrawtAccount/list", defaultColunms);
    table.setPaginationType("server");//服务器端分页
    table.setQueryParams(WithdrawtAccount.formParams());
    WithdrawtAccount.table = table.init();
  
});
